#!/bin/sh

set -e

# Script to do unpack of rootfs, ensures proper tear down
# of existing environment. Expects debian rootfs in
# /data/deb.tar.gz which it will delete after successful
# unpack of rootfs.

spath=$( cd "$(dirname "$0")" ; pwd -P )

if [ ! -f /data/androdeb/deb.tar.gz ]; then
	echo "Debian rootfs tar doesn't existing at /data/androdeb/deb.tar.gz"
	echo "Run androdeb with device connected first"
	exit 1
fi

if [ -d /data/androdeb/debian ]; then
	echo "androdeb environment already exists, doing a tear down"
	/data/androdeb/device-umount-all
	rm -rf /data/androdeb/debian
fi


gunzip /data/androdeb/deb.tar.gz
tar -xf /data/androdeb/deb.tar -C /data/androdeb/
rm /data/androdeb/deb.tar

echo "Unpack of rootfs successful!"
